/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaceGrafica;

import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;

/**
 *
 * @author Gean
 */
public class PanelQuestionario extends javax.swing.JPanel {

    /**
     * Creates new form PanelQuestionario
     */
    ArrayList<JRadioButton> radioButtons;
    public PanelQuestionario() {
        initComponents();
        radioButtons = new ArrayList<>();
        radioButtons.add(jRadioButtonOpcao1);
        radioButtons.add(jRadioButtonOpcao2);
        radioButtons.add(jRadioButtonOpcao3);
        radioButtons.add(jRadioButtonOpcao4);
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jRadioButtonOpcao4 = new javax.swing.JRadioButton();
        jRadioButtonOpcao2 = new javax.swing.JRadioButton();
        jRadioButtonOpcao3 = new javax.swing.JRadioButton();
        jLabelPergunta = new javax.swing.JLabel();
        jRadioButtonOpcao1 = new javax.swing.JRadioButton();

        jButton1.setText("Confirma");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jRadioButtonOpcao4.setText("Opção 4");
        jRadioButtonOpcao4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonOpcao4ActionPerformed(evt);
            }
        });

        jRadioButtonOpcao2.setText("Opção 2");
        jRadioButtonOpcao2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonOpcao2ActionPerformed(evt);
            }
        });

        jRadioButtonOpcao3.setText("Opção 3");
        jRadioButtonOpcao3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonOpcao3ActionPerformed(evt);
            }
        });

        jLabelPergunta.setText("Pergunta");

        jRadioButtonOpcao1.setText("Opção 1");
        jRadioButtonOpcao1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonOpcao1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButtonOpcao1)
                            .addComponent(jRadioButtonOpcao2)
                            .addComponent(jLabelPergunta, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(115, 329, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButtonOpcao4)
                            .addComponent(jRadioButtonOpcao3))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(54, 54, 54)
                .addComponent(jLabelPergunta)
                .addGap(77, 77, 77)
                .addComponent(jRadioButtonOpcao1)
                .addGap(37, 37, 37)
                .addComponent(jRadioButtonOpcao2)
                .addGap(37, 37, 37)
                .addComponent(jRadioButtonOpcao3)
                .addGap(32, 32, 32)
                .addComponent(jRadioButtonOpcao4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        for (int i = 0; i < 4; i++) {
            if (radioButtons.get(i).isSelected()) {
                System.out.println("Ok");
            }
        }
        JOptionPane.showMessageDialog(null, "Selecione uma das opções de resposta");
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jRadioButtonOpcao4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonOpcao4ActionPerformed
        for (int i = 0; i < 4; i++) {
            if (radioButtons.get(i).isSelected()) {
                radioButtons.get(i).setSelected(false);
            }
        }
        jRadioButtonOpcao4.setSelected(true);
    }//GEN-LAST:event_jRadioButtonOpcao4ActionPerformed

    private void jRadioButtonOpcao2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonOpcao2ActionPerformed
        for (int i = 0; i < 4; i++) {
            if (radioButtons.get(i).isSelected()) {
                radioButtons.get(i).setSelected(false);
            }
        }
        jRadioButtonOpcao2.setSelected(true);
    }//GEN-LAST:event_jRadioButtonOpcao2ActionPerformed

    private void jRadioButtonOpcao3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonOpcao3ActionPerformed
        for (int i = 0; i < 4; i++) {
            if (radioButtons.get(i).isSelected()) {
                radioButtons.get(i).setSelected(false);
            }
        }
        jRadioButtonOpcao3.setSelected(true);
    }//GEN-LAST:event_jRadioButtonOpcao3ActionPerformed

    private void jRadioButtonOpcao1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonOpcao1ActionPerformed
        for (int i = 0; i < 4; i++) {
            if (radioButtons.get(i).isSelected()) {
                radioButtons.get(i).setSelected(false);
            }
        }
        jRadioButtonOpcao1.setSelected(true);
    }//GEN-LAST:event_jRadioButtonOpcao1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabelPergunta;
    private javax.swing.JRadioButton jRadioButtonOpcao1;
    private javax.swing.JRadioButton jRadioButtonOpcao2;
    private javax.swing.JRadioButton jRadioButtonOpcao3;
    private javax.swing.JRadioButton jRadioButtonOpcao4;
    // End of variables declaration//GEN-END:variables
}
